//
//  LoadingView.m
//  QTZ
//
//  Created by ski on 2017/8/1.
//  Copyright © 2017年 ski. All rights reserved.
//

#import "JLCFLoadingView.h"

@interface JLCFLoadingView ()

@property (nonatomic, strong) UIView *shadowView;
@property (nonatomic, strong) UIView * bgView;
@property (nonatomic, strong) UIImageView *loadingView;


@end

@implementation JLCFLoadingView

+ (void)showInView:(UIView *)view {
    [view addSubview:[self shareView]];
    
}

+ (JLCFLoadingView *)shareView {
    static JLCFLoadingView *view;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        view = [[JLCFLoadingView alloc] init];
    });
    return view;
}

- (instancetype)init
{
    if (self = [super init]) {
        
        self.shadowView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, FULL_WIDTH, FULL_HEIGHT)];
        self.shadowView.backgroundColor = [UIColor colorWithWhite:0 alpha:.5];
        [self addSubview:self.shadowView];
        
//        self.bgView = [UIView new];
//        self.bgView.backgroundColor = QTZ_White;
//        self.bgView.layer.cornerRadius = 6;
//        self.bgView.width = self.bgView.height = 120;
//        self.bgView.centerX = self.shadowView.centerX;
//        self.bgView.centerY = self.shadowView.centerY - 50;
//        [self addSubview:self.bgView];
        
        self.loadingView = [[UIImageView alloc] initWithImage:[UIImage imageWithGIFNamed:@"Loading"]];
        [self.loadingView sizeToFit];
        self.loadingView.centerY = FULL_HEIGHT / 2;
        self.loadingView.centerX = FULL_WIDTH / 2;
        [self addSubview:self.loadingView];
        
//        NSMutableArray *imageArry = [NSMutableArray arrayWithCapacity:1];
//        for (int i = 1; i <= 7; i++) {
//            //图片名
//            NSString *name = [NSString stringWithFormat:@"Loading_%d", i];
//            //图片对象
//            UIImage *image = [UIImage imageNamed:name];
//            //image 添加到数组 imageArry
//            [imageArry addObject:image];
//        }
//        //设置动态播放的图片
//        self.loadingView.animationImages = imageArry;
//        //设置图片播放的时间
//        self.loadingView.animationDuration = 1;
//        //设置图片播放的次数
//        self.loadingView.animationRepeatCount = MAXFLOAT;
//        //播放图片
//        [self.loadingView startAnimating];
        
    }
    return self;
}

+ (void)dissmiss
{
    [[self shareView] removeFromSuperview];
}

@end
